package heap

// 查找方法

// 先从父类查找
func LookupMethodInClass(class *Class, name, descriptor string) *Method {
	for c := class; c != nil; c = c.superClass {
		for _, method := range c.methods {
			if method.name == name && method.descriptor == descriptor {
				return method
			}
		}
	}
	return nil
}

// 再从接口递归查找
func lookupMethodInInterface(intfs []*Class, name, descriptor string) *Method {
	for _, intf := range intfs {
		for _, method := range intf.methods {
			if method.name == name && method.descriptor == descriptor {
				return method
			}
		}
		method := lookupMethodInInterface(intf.interfaces, name, descriptor)
		if method != nil {
			return method
		}
	}
	return nil
}
